﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiTeach.Tools
{
    public  class FileHelper
    {
        public string fileroot = "";

        /// <summary>
        /// 获取项目文件下文件全路径
        /// </summary>
        /// <param name="prefix">项目文件夹名称</param>
        /// <param name="fileName">文件名称</param>
        /// <returns></returns>
        public string GetFinderFileFullPath(string prefix, string fileName)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string rootpath = path.Substring(0, path.LastIndexOf("\\"));
            rootpath = rootpath.Substring(0, rootpath.LastIndexOf("\\"));
            rootpath = rootpath.Substring(0, rootpath.LastIndexOf("\\"));
            return rootpath + prefix + fileName;
        }

        /// <summary>
        /// 获取可执行目录下的文件全路径
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <param name="prefix">项目文件夹名称</param>
        /// <returns>返回给定文件全路径</returns>
        public string GetExecutionDirectoryFileFullPath(string prefix, string fileName)
        {
            //string path = AppDomain.CurrentDomain.BaseDirectory;
            // string path = "C:\\xampp\\htdocs\\witeach-web\\public\\uploads\\";
            string path = this.GetFilePath()+"\\";
            //string rootpath = path.Substring(0, path.LastIndexOf("\\"));
            return prefix == "" ? path + fileName : path + prefix + fileName;
        }

        public string GetFilePath(){
            if (this.fileroot != "") { 
                return this.fileroot;
            }
            else
            {
                string strSql = "select value from  ta_conf where name='file_path'";
                 this.fileroot = SqlHelper.ExecuteScalar(strSql).ToString(); 
            }
            return this.fileroot;
        }
         
    }
}
